<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
        <meta name="format-detection" content="telephone=no" />
        <title>物流详情</title>
        <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
        <style type="text/css">
            .date-info{
                background: #ddd;
                color:#fff;
                font-size: 12px;
                display: inline-block;
                padding:0px 10px;
                border-radius: 3px;
                margin:10px 0;
            }
            .text-gray{
                color:#666;
                font-size: 14px;
            }
        </style>
    </head>
    <body>
        <div class="aui-content aui-content-padded" id="message-content">
        </div>
    </body>
    <script id="message-template" type="text/x-dot-template">
        {{ for(var i in it){ }}
        <div class="history-date aui-text-center">
            <div class="date-info">{{=formatTime(it[i].add_time)}}</div>
        </div>
        <div class="aui-card aui-noborder">
            <ul class="aui-list-view">
                {{?it[i].status==1}}<!-- 未付款 -->
                <li class="aui-list-view-cell aui-text-info">
                    订单通知
                </li>
                <li class="aui-list-view-cell text-gray">
                    货品 {{=it[i].title}} 已被买家{{=it[i].buyer_nickname?it[i].buyer_nickname:''}}拍下，等待买家付款
                </li>
                {{??it[i].status==2}}<!-- 已付款 -->
                <li class="aui-list-view-cell aui-text-info">
                    买家已付款
                </li>
                <li class="aui-list-view-cell text-gray">
                    买家{{=it[i].buyer_nickname?it[i].buyer_nickname:''}}已支付 {{=it[i].title}} 的货款，等待发货
                </li>
                {{??it[i].status==3}}<!-- 已发货 -->
                <li class="aui-list-view-cell aui-text-primary">
                    卖家已发货
                </li>
                <li class="aui-list-view-cell text-gray">
                    您订购的货品 {{=it[i].title}} 已经发货。
                </li>
                {{??it[i].status==4}}<!-- 已收货 -->
                <li class="aui-list-view-cell aui-text-info">
                    买家已收货
                </li>
                <li class="aui-list-view-cell text-gray">
                    货品 {{=it[i].title}} 已被买家{{=it[i].buyer_nickname?it[i].buyer_nickname:''}}签收
                </li>
                {{??it[i].status==5}}<!-- 已评价 -->
                <li class="aui-list-view-cell aui-text-info">
                    买家已评论
                </li>
                <li class="aui-list-view-cell text-gray">
                    买家{{=it[i].buyer_nickname?it[i].buyer_nickname:''}}评论了货品 {{=it[i].title}}
                </li>
                {{??it[i].status==6}}<!-- 未发货申请退款 -->
                <li class="aui-list-view-cell aui-text-info">
                    买家申请退款
                </li>
                <li class="aui-list-view-cell text-gray">
                    货品 {{=it[i].title}} 被买家{{=it[i].buyer_nickname?it[i].buyer_nickname:''}}申请了退款
                </li>
                {{??it[i].status==7}}<!-- 已发货申请退款 -->
                <li class="aui-list-view-cell aui-text-info">
                    买家已申请退款
                </li>
                <li class="aui-list-view-cell text-gray">
                    货品 {{=it[i].title}} 被买家申请了退款
                </li>
                {{??it[i].status==0}}<!-- 交易关闭 -->
                <li class="aui-list-view-cell aui-text-default">
                    交易已关闭
                </li>
                <li class="aui-list-view-cell text-gray">
                    货品 {{=it[i].title}} 的交易已关闭
                </li>
                {{?}}
                <li class="aui-list-view-cell" onclick="go2Order({{=it[i].order_id}},{{=it[i].status}},{{=it[i].buyer_id}});">
                    <div class="aui-arrow-right text-gray">
                        查看详情
                    </div>
                </li>
            </ul>
        </div>
        {{ } }}
    </script>
    <script type="text/javascript" src="../../script/api.js"></script>
    <script type="text/javascript" src="../../script/common.js"></script>
    <script type="text/javascript" src="../../script/doT.min.js"></script>
    <script type="text/javascript" src="../../script/jquery-1.11.3.js"></script>

    <script type="text/javascript">
        var isLock=false;
        var page=1;
        apiready = function() {
            api.parseTapmode();

            api.setRefreshHeaderInfo({
                visible : true,
                loadingImg : 'widget://image/ptr_pull.png',
                bgColor : '#efeff4',
                textColor : '#959595',
                textDown : '下拉刷新',
                textUp : '松开刷新',
                showTime : true
            }, function(ret, err) {
                page = 1;
                isLock=false;
                loadData();
            });


             // 监听是否达到底部上拉加载
             api.addEventListener({
                name : 'scrolltobottom'
            }, function(ret, err) {
                page++;
                if (!isLock)loadData(page);
            });

            api.refreshHeaderLoading();


            //计数器清零
            clearCount();
        }

        function loadData(toPage){
            getStorageAll();

            toPage=toPage?toPage:page;
            if(toPage==1)api.refreshHeaderLoading();

            var url='Order/expressInformationList/userName/'+user_name+'/page/'+toPage;

            if(!isLock){
                isLock = true;
                ajaxRequest(url, 'get', {}, function (ret, err) {
                    api.refreshHeaderLoadDone();
                    if (ret.status == 1) {
                        // alert(JSON.stringify(ret.msg));

                        var tpl = $api.byId('message-template').text;
                        var tempFn = doT.template(tpl);

                        if (toPage > 1) {
                            if(!$.trim(ret.msg)){
                                return;
                            }
                            $('#message-content').show().append(tempFn(ret.msg));
                        }else{
                            $('#message-content').show().html(tempFn(ret.msg));
                        }
                    } else {
                        api.toast({
                            msg: ret.msg,
                            duration: 2000,
                            location: 'bottom'
                        });
                    }
                    isLock=false;
                });
            }
        }

        function go2Order(orderId,orderStatus,buyerId){
            getStorageAll();
            if(buyerId==user_id){
                api.openWin({
                    name: 'orderInfo',
                    url: 'orderInfo.html',
                    pageParam: {
                        orderId: orderId,
                        orderStatus:orderStatus
                    },
                    //delay: 300
                });
            }else{
                api.openWin({
                    name: 'orderInfoBySeller',
                    url: 'orderInfoBySeller.html',
                    pageParam: {
                        orderId: orderId,
                        orderStatus:orderStatus
                    },
                    //delay: 300
                });
            }
        }


       function clearCount(){
             getStorageAll();
             ajaxRequest('/User/smsCountReduce/type/2?userName='+user_name, 'post', {}, function (ret, err) {
                   api.sendEvent({
                    name: 'clearMessageCountExpress'
                });
             });
       }


    function formatTime (timespan) {

          var dateTime = new Date(timespan*1000);

          var year = dateTime.getFullYear();
          var month = dateTime.getMonth() + 1;
          var day = dateTime.getDate();
          var hour = dateTime.getHours();
          var minute = dateTime.getMinutes();
          var second = dateTime.getSeconds();
          var now = new Date();
          var now_new = Date.parse(now.toDateString());  //typescript转换写法

          var milliseconds = 0;
          var timeSpanStr;

          milliseconds = now_new - timespan;

        if (milliseconds <= 1000 * 60 * 1) {
            timeSpanStr = '刚刚';
        }
        else if (1000 * 60 * 1 < milliseconds && milliseconds <= 1000 * 60 * 60) {
            timeSpanStr = Math.round((milliseconds / (1000 * 60))) + '分钟前';
        }
        else if (1000 * 60 * 60 * 1 < milliseconds && milliseconds <= 1000 * 60 * 60 * 24) {
            timeSpanStr = Math.round(milliseconds / (1000 * 60 * 60)) + '小时前';
        } else {
            timeSpanStr = year + '年' + month + '月' + day + '日';
        }
        return timeSpanStr;
    }

    </script>
</html>
